<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>添加借款用户</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" id="id" value="${userInfo.id}">
    <input type="hidden" id="show" value="${show}">
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>手机号码:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input mobile" lay-verify="phone" placeholder="请输入手机号码" value="${userInfo.mobile}">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>真实姓名:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input userName" lay-verify="required" placeholder="请输入真实姓名" value="${userInfo.userName}">
		</div>
	</div>
	<div class="layui-row">
		<div class="magb15 layui-col-md4 layui-col-xs12">
			<label class="layui-form-label"><span style="color:red;">*</span>性别:</label>
			<div class="layui-input-block userSex">
			  <c:if test="${userInfo.sex == 1}">
			    <input type="radio" name="sex" value="0" title="男">
				<input type="radio" name="sex" value="1" title="女" checked>
			  </c:if>
			  <c:if test="${userInfo.sex == 0}">
			    <input type="radio" name="sex" value="0" title="男" checked>
				<input type="radio" name="sex" value="1" title="女">
			  </c:if>
			  <c:if test="${userInfo.sex == null}">
			    <input type="radio" name="sex" value="0" title="男" checked>
				<input type="radio" name="sex" value="1" title="女">
			  </c:if>
			</div>
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label">身份证号:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input identityCard" lay-verify="NEWIdentity" placeholder="请输入身份证号" value="${userInfo.identityCard}">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label">邮箱:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input mailbox" lay-verify="NEWEmail" placeholder="请输入邮箱" value="${userInfo.mailbox}">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<div class="layui-input-block">
			<button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addUserInfo">提交</button>
			<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary" onclick="close_self();">取消</button>
		</div>
	</div>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    
    form.verify({
    	NEWEmail : function(value, item){
    		if(value != null && value != ""){
    			var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
    			if(!re.test(value)){
    				return '邮箱格式不正确';
    			}
    		}
    	},
    	NEWIdentity : function(value, item){
    		if(value != null && value != ""){
    			var re = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
    			if(!re.test(value)){
    				return '身份证格式不正确';
    			}
    		}
    	}
	});
    form.on("submit(addUserInfo)",function(data){
        //弹出loading
    	var url =""; var record="";
    	if($("#id").val() != ""){
    		url="/admin/userinfo/update";
    		record="编辑借款用户:";
    	}else{
    		url="/admin/userinfo/insert";
    		record="添加借款用户:";
    	}
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post(url,{
        	 id  : $("#id").val(),
        	 mobile : $(".mobile").val(),  
             userName : $(".userName").val(),
             mailbox : $(".mailbox").val(),
             identityCard: $(".identityCard").val(),  
             sex: data.field.sex, 
             record : record
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功");
        		 setTimeout(function(){
        			  if($("#show").val()=="1"){
     	        		window.location.href="/admin/userinfo/showlist";
     	        	  }else{
     	        		window.location.href="/admin/userinfo/detail";
     	        	  }
        	        },2000); 
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
})
function close_self(){
	 if($("#show").val()=="1"){
  		window.location.href="/admin/userinfo/showlist";
  	  }else{
  		window.location.href="/admin/userinfo/detail";
  	  }
}
</script>
</body>
</html>